Quality Test

`this is the procedure used to test the Speech Pack external
`beside this procedure there are two others included: DoError and DoWaitVoice

`before release of this version of Speech Pack this procedure must have
`been executed succesfully with at least these configurations:
`Macintosh IIx 8/140, System 7.1 US, 4D 2.2.3
`Macintosh PowerBook Duo 210, System 7.1 US, 4D 3.0.5
`Macintosh IIx 8/140, System 6.0.8 Int, 4D 2.2.3
`Macintosh IIx 8/140, System 7.1 US, 4D 3.0.5
`Macintosh Plus 4/20, System 6.0.8 Int, 4D Server Demo 1.0.5
`  and Macintosh IIx 8/140, System 7.1 US, 4D Client Demo 1.0.5
`all using the latest available version of Speech Manager and PlainTalk
`each function has been tested more extensively during development

`declarations from the Speech Pack Language Reference:
C_INTEGER($err;$speechref;$present;$count;$rate;$pitch;$i)
C_INTEGER($gender;$age;$language;$region;$script)
C_LONGINT($modul)
C_STRING(4;$creator;$id)
C_STRING(15;$mgrvers;$packvers)
C_STRING(63;$voicename)
C_STRING(255;$comment;$message;$phoneme;$path)

`additional declarations for use in this procedure
C_INTEGER($org_rate;$org_pitch)
C_STRING(255;$test_str;$alert)
C_TEXT($test_txt)
ARRAY TEXT(SpeechArray;0)

$test_str:="Testing Speech Manager 1.2.3"
$test_txt:="Hello, you are now testing Speech Pack and the Speech Manager on your Macintosh"

`get copyright message
SP COPYRIGHT ($message)

`get version numbers of Speech Mgr and Speech Pack
SP VERSION ($mgrvers;$packvers)

`compose text to display
`if $mgrvers is empty the Speech Mgr is not installed
$alert:=$alert+"Speech Manager: "+($mgrvers*Num($mgrvers#""))+("N/A"*Num($mgrvers=""))+Char(13)
$alert:=$alert+"4D Speech Pack: "+$packvers+(2*Char(13))
$alert:=$alert+$message

`display text on screen
ALERT($alert)

$count:=0
For ($i;0;31)
  $count:=$count+SP Features ($i)
End for 
If ($count#6)
  DoError ($count;"Incorrect number of featureflags set.")
End if 

$present:=SP Can speak 

If ($present>0)
  
  `test the Quick Speak functions
  $voicename:="*"`using the default normal voice
  $err:=SP Speak String ($voicename;$test_str)
  DoError ($err;"")
  $err:=SP Speak Text ($voicename;$test_txt;1;1)
  DoError ($err;"")
  
  $voicename:="#"`using the default robot voice
  $err:=SP Speak String ($voicename;$test_str)
  DoError ($err;"")
  $err:=SP Speak Text ($voicename;$test_txt;1;1)
  DoError ($err;"")
  
  $message:="Select a voice for testing:"
  $voicename:="*"
  $rate:=0
  $pitch:=0
  $modul:=-1
  $err:=SP Pick Voice (0;0;$message;$voicename;$rate;$pitch;$modul;0)
  If ($err#0)
    $voicename:="Brenda"
  End if 
  
  $err:=SP Speak String ($voicename;$test_str)
  DoError ($err;"")
  $err:=SP Speak Text ($voicename;$test_txt;1;1)
  DoError ($err;"")
  $err:=SP Speak Text ($voicename;$test_txt;1;6)
  DoError ($err;"")

  `test the BackWard Compatibility functions
  TRACE
  Say ($test_str;0)`use normal voice, rate and pitch
  Say ($test_str;1)`use robot voice and normal rate and pitch
  Say ($test_str;0;140;80)`use normal voice but other rate and pitch
  
  PARLE ($test_str)
  NO TRACE
  
  `try to open all voices and let them speak at the same time
  SP VOICES ARRAY ("SpeechArray")`first get the array with voicenames
  $count:=Size of array(SpeechArray)`count the number of voices
  
  ALERT("Now start speaking with all voices ("+String($count)+") if possible…")
  For ($i;1;$count)
    $err:=SP Open Voice (SpeechArray$i;$speechref)
    
    If ($i<=10)&($err=-241)
      DoError ($err;"Can't open 10 channels, not enough memory?")
    End if 
    If ($i>10)&($err=0)
      DoError ($err;"Can open more than 10 channels?")
    End if 
    
    If ($err=0)
      $err:=SP Voice Text ($speechref;$test_txt;1;1;4)`pass text and pause before start speech
    End if 
  End for 
  $err:=SP Voice Cont (-1)`now continue all voices
  While (SP Speaking >0)`while anyone is speaking wait for it to finish
    IDLE
  End while 
  $err:=SP Close Voice (-1)`close all channels

  `test the other functions in a loop, opening several speech channels
  $count:=SP Count voices 
  
  For ($i;1;$count)
    `test general information routines
    $err:=SP Voicename ($i;$voicename)
    $err:=SP Voice Info ($voicename;$comment;$gender;$age)
    $err:=SP Language ($voicename;$language;$region;$script)
    
    `compose text to display
    $alert:="Voice: "+$voicename+(2*Char(13))
    $alert:=$alert+"Comment: "+$comment+Char(13)
    $alert:=$alert+"Gender: "+("Neuter"*Num($gender=0))+("Male"*Num($gender=1))+("Female"*Num($gender=2))+Char(13)
    $alert:=$alert+"Age: "+String($age)+" year"+Char(13)
    If ($language#0)|($region#0)|($script#0)
      $alert:=$alert+"Language: "+String($language)+Char(13)
      $alert:=$alert+"Region: "+String($language)+Char(13)
      $alert:=$alert+"Script: "+String($language)+Char(13)
    End if 
    
    `display text on screen
    ALERT($alert)
    
    `get more info
    $err:=SP Voice Type ($voicename;$creator;$id;$path)
    
    `compose text to display
    $alert:="Voice: "+$voicename+(2*Char(13))
    $alert:=$alert+"Creator: "+$creator+Char(13)
    $alert:=$alert+"ID: "+$id+Char(13)
    $alert:=$alert+"Data stored in disk file:"+Char(13)+$path+Char(13)
    
    `display text on screen
    ALERT($alert)
    
    $err:=SP Open Voice ($voicename;$speechref)
    If ($err=0)
      
      $err:=SP Voice String ($speechref;":-16395,0")
      DoError ($err;"")
      DoWaitVoice ($speechref)
      
      $err:=SP Voice String ($speechref;"René")
      DoError ($err;"")
      DoWaitVoice ($speechref)
      
      $err:=SP Voice String ($speechref;"René")
      DoError ($err;"")
      `unless you have a fast computer any non-PlainTalk voice
      `is probably already finished
      $err:=SP Voice Pause ($speechref)
      DoError ($err;"")
      ALERT("Now speaking will continue…")
      $err:=SP Voice Cont ($speechref)
      DoError ($err;"")
      DoWaitVoice ($speechref)
      
      $err:=SP Voice String ($speechref;$test_str)
      DoError ($err;"")
      DoWaitVoice ($speechref)
      
      $err:=SP Voice Text ($speechref;$test_txt;1;1;6)
      If ($err=0)
        
        If (SP Voice busy ($speechref)=2)
          $err:=SP Voice Cont ($speechref)
          DoError ($err;"")
        Else 
          DoError (2;"Speech should be paused.")
        End if 
        
      Else 
        DoError ($err;"")
      End if 
      
      $err:=SP Voice Text ($speechref;$test_txt;1;6;0)
      DoWaitVoice ($speechref)
      Case of 
        : ($err=0)
          DoError (-242;"Should return an error here…")
        : ($err=-242)
          `nothing          
        Else 
          DoError ($err;"")
      End case 
      
      $err:=SP Voice code ($speechref;$test_str;$phoneme;0)
      If ($err<0)
        DoError ($err;"")
      Else 
        ALERT("String "+Char(34)+$test_str+Char(34)+" is converted to:"+Char(13)+$phoneme)
      End if 
      
      $err:=SP Voice code ($speechref;$test_str;$phoneme;1)
      If ($err<0)
        DoError ($err;"")
      Else 
        ALERT("String "+Char(34)+$test_str+Char(34)+" is converted to:"+Char(13)+$phoneme)
      End if 
      
      `store 8-bit sound data as resource in 4D file
      $err:=SP Voice sound ($speechref;$test_str;$voicename+".RES8-0";"NONE";4)
      If ($creator#"gala")&($err=0)
        DoError (-231;"Should return error because not a PlainTalk voice.")
      Else 
        If ($err#-231)
          PLAY($voicename+".RES8-0")
          DoError ($err;"")
        End if 
      End if 
      
      `store 8-bit sound data as resource in 4D file
      `with 3:1 compression
      $err:=SP Voice sound ($speechref;$test_str;$voicename+".RES8-3";"MAC3";4)
      If ($creator#"gala")&($err=0)
        DoError (-231;"Should return error because not a PlainTalk voice.")
      Else 
        If ($err#-231)
          PLAY($voicename+".RES8-3")
          DoError ($err;"")
        End if 
      End if 
      
      `store 8-bit sound data as resource in 4D file
      `with 6:1 compression
      $err:=SP Voice sound ($speechref;$test_str;$voicename+".RES8-6";"MAC6";4)
      If ($creator#"gala")&($err=0)
        DoError (-231;"Should return error because not a PlainTalk voice.")
      Else 
        If ($err#-231)
          PLAY($voicename+".RES8-6")
          DoError ($err;"")
        End if 
      End if 
      
      `store 16-bit sound data as resource in Finder file
      $err:=SP Voice sound ($speechref;$test_str;"desk:"+$voicename+".FNDR16";"NONE";7)
      If ($creator#"gala")&($err=0)
        DoError (-231;"Should return error because not a PlainTalk voice.")
      Else 
        If ($err#-231)
          DoError ($err;"")
        End if 
      End if 
      
      `test get an set attributes and reset channel
      $err:=SP Get Attr ($speechref;$org_rate;$org_pitch)
      DoError ($err;"")
      $err:=SP Set Attr ($speechref;$org_rate-10;$org_pitch-25)
      DoError ($err;"")
      `the rate and pitch can be changed by synthesizer to correct values
      $err:=SP Get Attr ($speechref;$rate;$pitch)
      DoError ($err;"")
      $err:=SP Voice reset ($speechref)
      DoError ($err;"")
      $err:=SP Get Attr ($speechref;$rate;$pitch)
      DoError ($err;"")
      If ($org_rate#$rate)
        $err:=SP Get Attr ($speechref;$rate;$pitch)
        DoError (0;"Rate after reset is different from original value.")
      End if 
      If ($org_pitch#$pitch)
        $err:=SP Get Attr ($speechref;$rate;$pitch)
        DoError (0;"Rate after reset is different from original value.")
      End if 
      
      `close thise voice
      $err:=SP Close Voice ($speechref)
      DoError ($err;"")
    Else 
      
      DoError ($err;"")
      
      If ($speechref#0)
        DoError ($err;"reference value isn't set to zero.")
      End if 
      
    End if 
    
  End for 
  
Else `can not speak because Speech Mgr not present or Speech Pack not set up properly
  
  DoError (-4;"Unable to use Speech Pack.")
  
End if 

DoError procedure
If ($1#0)
  If ($2="")
    $2:="Sorry, an error occured."
  End if 
  
  ALERT($2+String($1))
  TRACE
End if 

DoWaitVoice procedure
While (SP Voice busy ($1)=1)
  IDLE
End while